package com.gts.sofa.controller;

import com.gts.sofa.impl.MyMathCalculator;
import com.gts.sofa.proxy.DynamicProxyFactory;
import com.gts.sofa.service.Calculator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class DynamicProxyController {


    @RequestMapping("/add")
    public void add(){

        MyMathCalculator myMathCalculator = new MyMathCalculator();
        DynamicProxyFactory dynamicProxyFactory = new DynamicProxyFactory(myMathCalculator);
        //这里是打印的结果是一个proxy
        System.err.println(DynamicProxyFactory.getProxyInstance().getClass());
        Calculator calculator = (Calculator)DynamicProxyFactory.getProxyInstance();




        System.out.println(calculator.add(12,12));

        System.err.println(calculator.sub(23,21));

        System.out.println(calculator.div(12,1));
    }





}
